#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1000+10;
const int maxm = 3e6+10;
const int mod = 998244353;
int n,m;
bool f[maxn][maxn];
char a[maxm];
set<string> st;
void dfs(int x,string s) {
//	cerr<<x<<' '<<s<<'\n';
	if(x == n+1) {
		st.insert(s);
		return ;
	}
	s += a[x];
	for(int i = x+1; i <= n+1; i++) {
		if(f[x+1][i-1]) dfs(i,s);
	}
}
bool check() {
	for(int i = 1; i < n; i++) if(a[i] == a[i+1]) return false;
	return true;
}
void Solve() {
	cin >> (a+1); n = strlen(a+1);
	if(check()) {
		int len = n; if(a[1] == 'A') len--; if(a[n] == 'B') len--;
		cout<<len/2+1<<'\n';
		return;
	}
	for(int i = 1; i <= n+1; i++) {
		f[i][i-1] = true;
	} 
	for(int len = 2; len <= n; len += 2) {
		for(int i = 1; i+len-1 <= n; i++) {
			int j = i + len - 1;
			if(a[i] != 'A' || a[j] != 'B') f[i][j] |= f[i+1][j-1];
			for(int k = i; k <= j; k += 2) {
				f[i][j] |= (f[i][k-1] && f[k][j]);
			}
		}
	}/*
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++)
			cout<<f[i][j]<<' ';
		cout<<'\n';
	}*/
	for(int i = 0; i <= n; i += 2) if(f[1][i]) dfs(i+1,"");
	cout<<st.size()<<'\n';
}
int main() {
	freopen("song.in","r",stdin);
	freopen("song.out","w",stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
	Solve();
	return 0;
}
/*
BAABB
BAA
BBB
ABB
A
B

BBBABA
BABA
BBBA
BA
BB
\emptyset 
*/

